package cn.com.qiancheng.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.com.qiancheng.dto.Evaluation;
import cn.com.qiancheng.dto.Student;
import cn.com.qiancheng.util.DbUtil;

public class UnFinishDao {
	public List<Evaluation> searchUnFinishDao(Student stu) {
		List<Evaluation> list = new ArrayList<>();
		try {
			Connection con = DbUtil.openConnection();
			String sql = "SELECT f_eva_id FROM t_unfinish WHERE t_unfinish.f_stu_id =? AND e_flag = 0";
			PreparedStatement stat = con.prepareStatement(sql);
			stat.setInt(1, stu.getStuId());
			ResultSet rs = stat.executeQuery();
			while (rs.next()) {
				Evaluation eva = new EvaluationDao().sreachEvaluation(rs.getInt("f_eva_id"));
				eva.setStuId(stu.getStuId());
				eva.setStuPassword(stu.getStuPassword());
				eva.setStuUserName(stu.getStuUserName());
				eva.settClass(new TrinerClassDao().sreachTrinerClass(stu.getStuClass()));
				list.add(eva);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				DbUtil.closeConnection();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}
}
